package menu

import (
	"context"
	"net/http"

	"mall/service/backend/api/internal/logic/system/menu"
	"mall/service/backend/api/internal/svc"

	"github.com/zeromicro/go-zero/rest/httpx"
)

// swagger:route get /sys/menu/role/list menu GetMenuListByRole
//
// Get menu list by role | 获取菜单列表
//
// Get menu list by role | 获取菜单列表
//
// Responses:
//  200: SystemMenuListResp

func GetMenuListByRoleHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
	return func(w http.ResponseWriter, r *http.Request) {
		ctx := context.WithValue(r.Context(), "lang", r.Header.Get("Accept-Language"))
		l := menu.NewGetMenuListByRoleLogic(ctx, svcCtx)
		resp, err := l.GetMenuListByRole()
		if err != nil {
			err = svcCtx.Trans.TransError(ctx, err)
			httpx.ErrorCtx(ctx, w, err)
		} else {
			httpx.OkJsonCtx(ctx, w, resp)
		}
	}
}
